<?php
require_once('Zend/Controller/Plugin/Abstract.php');

class Kbs_Controller_Plugin_Common extends Zend_Controller_Plugin_Abstract
{
    //protected $_bootstrap = null;

    public function routeShutdown(Zend_Controller_Request_Abstract $request)
    {
        $module = $request->getModuleName();

        $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');

        /**
         * Modules bootstrap

        $resource = $bootstrap->getPluginResource('Modules');
        $moduleBootstraps = $resource->getExecutedBootstraps();
        if (isset($moduleBootstraps[$module])) {
            $moduleBootstrap = $moduleBootstraps[$module];
        }
         */

        if ('admin' == $module) {
            $bootstrap->bootstrap('AuthHttp');
        }
        
        $bootstrap->bootstrap('View');
        $view = $bootstrap->getResource('View');
        $moduleParams = $view->$module;

        $view->addBasePath($moduleParams['basePath'])
             ->addHelperPath($moduleParams['helperPath'],
                             $moduleParams['helperPathPrefix']);

        $bootstrap->bootstrap('Layout');
        $layout = $bootstrap->getResource('Layout');
        $layout->setLayoutPath($moduleParams['layoutPath'])
               ->setLayout($moduleParams['layout']);
    }

}